from flask import Blueprint, render_template, views, make_response
from utils.captcha import Captcha
from io import BytesIO

blueprint = Blueprint("front", __name__)

@blueprint.route("/")
def index():
    return render_template("front/front_base.html")

# 用户注册视图
class RegisterViews(views.MethodView):
    def get(self):
        return render_template("front/front_register.html")

# 生成图片验证码
@blueprint.route("/captcha")
def capatch():
    text, image = Captcha.generate_graph_captcha()
    print(text)
    out = BytesIO()
    image.save(out, "png")
    out.seek(0)
    response = make_response(out.read())
    response.content_type = "image/png"
    return response

blueprint.add_url_rule("/register", view_func=RegisterViews.as_view("register"))